package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.login.wechat.DeleteWxcodeBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.WxcodeDao;
import com.zhuss.core.db.entity.Wxcode;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.OceanException;
import com.zhuss.util.JsonUtil;

/**
 * 删除绑定openId processor
 * @Author: zhushanshuo
 * @Date: 2020/03/26 10:59
 */
@Component("wxcodeDelete")
public class WxcodeDelete extends AbstractProcessor<Object, DeleteWxcodeBo> implements Processor<Object, DeleteWxcodeBo> {

    @Autowired
    private WxcodeDao wxcodeDao;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteWxcodeBo bo) throws OceanException {
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteWxcodeBo param) throws OceanException {
    	Long userId = param.getUserId();
    	
    	Wxcode record = new Wxcode();
    	record.setUserId(userId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	wxcodeDao.delete(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteWxcodeBo param) throws OceanException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.用户删除绑定openId.key());
    	record.setTargetId(param.getUserId());
    	record.setTargetName("" + param.getUserId());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
